<?php
/**
 * Created by PhpStorm.
 * User: sunfan
 * Date: 2017/3/21
 * Time: 16:33
 */

namespace Admin\Model;


use Think\Model;

class EnterpriseModel extends Model
{

    /* 自动验证规则 */
    protected $_validate = array(
        array('name', 'require', '企业名称不能为空' ),
        array('admin_name','require','管理员名称必须得填'),
        array('address','require','企业地址必须填写')
    );
    /**
     * 文件模型自动完成
     * @var array
     */
    protected $_auto = array(
        array('admin_id', 'session', self::MODEL_INSERT, 'function', 'user_auth.uid'),
        array('create_time', NOW_TIME, self::MODEL_INSERT),
    );

    public function store($data){

        if($this->create()){
          $add =  $this->add($data);
          if($add){
              return true;
          }else{
              $this->error="添加出错，请稍后再试！";
          }
        }
        return false;
    }

    public function update(){
       $data = $_POST;
       $id = I('post.id',0,'intval');
        if($this->create()){
            $edit =  $this->where(array('id'=>$id))->save($data);
            if($edit){
                return true;
            }else{
                $this->error="添加出错，请稍后再试！";
            }
        }
        return false;
    }
}